home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / GCC / CLIB / !clib / h / stdio < prev    next >
Text File  |  1997-05-22  |  10KB  |  306 lines

  1. /* stdio.h
  2.  
  3.    For use with the GNU compilers and the SharedCLibrary.
  4.    (c) Copyright 1997, Nick Burrett.  */
  5.  
  6. #ifndef __STDIO_H
  7. #define __STDIO_H
  8.  
  9. #ifndef __STDDEF_H
  10. #include <stddef.h>
  11. #endif
  12.  
  13. #ifdef __GNUC__
  14. #define __need___va_list
  15. #include <stdarg.h>
  16. #else
  17. /* Insert a definition of __va_list for your compiler here.
  18.    Copy the definition of 'va_list' in <stddef.h> but prefix it
  19.    with two underscores.  Then commend out the #error line below.  */
  20. #error need definition of __va_list for your compiler
  21. #endif
  22.  
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26.  
  27. #define __LIB_VERSION 300
  28.  
  29. typedef struct __fpos_t_struct
  30. {
  31.   unsigned long __lo;
  32. } fpos_t;
  33.  
  34. typedef struct __FILE_struct
  35. {
  36.   unsigned char *__ptr;
  37.   int __icnt;
  38.   int __ocnt;
  39.   int __flag;
  40.   unsigned char *__base;
  41.   void *__file;
  42.   long __pos;
  43.   int __bufsiz;
  44.   int __signature;
  45.   int *internal;
  46. } FILE;
  47.  
  48. #define _IOEOF 0x40
  49. #define _IOERR 0x80
  50. /* Full buffering.  */
  51. #define _IOFBF 0x100
  52. /* Line buffering.  */
  53. #define _IOLBF 0x200
  54. /* No buffering.  */
  55. #define _IONBF 0x400
  56. /* Default buffer size.  */
  57. #define BUFSIZ (4096)
  58. /* End of file character.  */
  59. #define EOF (-1)
  60.  
  61. /* Maximum number of files that can be open at once.  */
  62. #define FOPEN_MAX 8
  63. #define _SYS_OPEN 16
  64.  
  65. /* Maximum length of a filename.  */
  66. #define FILENAME_MAX 80
  67.  
  68.  
  69. /* Seek from beginning of file.  */
  70. #ifndef SEEK_SET
  71. #define SEEK_SET 0
  72. #endif
  73. /* Seek from current position.  */
  74. #ifndef SEEK_CUR
  75. #define SEEK_CUR 1
  76. #endif
  77. /* Seek from end of file.  */
  78. #ifndef SEEK_END
  79. #define SEEK_END 2
  80. #endif
  81.  
  82. /* How long an array of chars must be to be passed to tmpnam.  */
  83. #define L_tmpnam 20
  84. /* The maximum number of unique filenames generated by tmpnam.  */
  85. #define TMP_MAX 1000000000
  86.  
  87. /* Standard streams.  */
  88. extern FILE __iob[];
  89.  
  90. #define stdin (&__iob[0])
  91. #define stdout (&__iob[1])
  92. #define stderr (&__iob[2])
  93.  
  94. /* Delete file 'filename'.  */
  95. extern int remove (const char *filename);
  96.  
  97. /* Rename a file called 'oldname' to 'newname'. If rename fails
  98.    it returns -1.  */
  99. extern int rename (const char *oldname, const char *newname);
  100.  
  101. /* Create a temporary binary file for updade mode, as if calling
  102.    fopen with mode "wb+".  The file is deleted automatically when
  103.    it is closed or when the program terminates.  */
  104. extern FILE *tmpfile (void);
  105.  
  106. /* Construct and return a file name that is a valid and does not
  107.    name any existing file. If 'result' is null, the return value
  108.    points to an internal static string. Otherwise, 'result' points
  109.    to an array of at least L_tmpnam chars.  */
  110. extern char *tmpnam (char *result);
  111.  
  112. /* Cause 'stream' to be closed and the connection to the corresponding
  113.    file to be broken.  All buffered output is written and buffered
  114.    input is discarded. Returns 0 on success, EOF if an error was detected.  */
  115. extern int fclose (FILE *stream);
  116.  
  117. /* Cause any buffered output on 'stream' to be delivered to the file.
  118.    If 'stream' is null, then fflush causes buffered output on all open
  119.    output streams. Returns EOF if a write error occurs, zero otherwise.  */
  120. extern int fflush (FILE *stream);
  121.  
  122. /* Open a stream for I/O to the file 'filename' and return a pointer
  123.    to the stream.  */
  124. extern FILE *fopen (const char *filename, const char *opentype);
  125.  
  126. /* Close the stream 'stream', ignoring any errors. Then 'filename'
  127.    is opened with 'opentype' with the same stream object 'stream'.
  128.    Returns null on failure.  Usually used to connect to standard
  129.    streams e.g. stdin, stdout or stderr.  */
  130. extern FILE *freopen (const char *filename, const char *opentype, FILE *stream);
  131.  
  132. /* Set file buffering for 'stream'. If 'buf' is null, then
  133.    file buffering is turned off, otherwise we use full file buffering.  */
  134. extern void setbuf (FILE *stream, char *buf);
  135.  
  136. /* Specify that the stream 'stream' should have the buffering mode
  137.    'mode', which can be either _IOFBF (full buffering), _IOLBF (line
  138.    buffering) or _IONBF (unbuffered input/output).
  139.  
  140.    If 'buf' is null, then setvbuf allocates a buffer itself using
  141.    malloc. This is freed when the stream is closed.
  142.  
  143.    Otherwise 'buf' is a character array of 'size' characters.  */
  144. extern int setvbuf (FILE *stream, char *buf, int mode, size_t size);
  145.  
  146. /* Print the optional arguments under control of the template
  147.    string 'fmt' to the stream stdout. Returns the number of characters
  148.    printed, or a negative value if there was an output error.  */
  149. extern int printf (const char *fmt, ...);
  150.  
  151. /* Similar to printf except the output is written to the stream
  152.    'stream' instead of stdout.  */
  153. extern int fprintf (FILE *stream, const char *fmt, ...);
  154.  
  155. /* Similar to printf except the output is stored in the array
  156.    'string'. A null terminating character is also written.  */
  157. extern int sprintf (char *string, const char *fmt, ...);
  158.  
  159. /* Read formatted input from the stream stdin under control
  160.    of the template 'fmt'. Returns the number of successful
  161.    assignments.  */
  162. extern int scanf (const char *fmt, ...);
  163.  
  164. /* Similar to scanf but reads from the stream 'stream'.  */
  165. extern int fscanf (FILE *stream, const char *fmt, ...);
  166.  
  167. /* Similar to scanf but reads from the array 'string'.  */
  168. extern int sscanf (const char *string, const char *fmt, ...);
  169.  
  170. /* Similar to printf but it takes an argument list pointer 'ap'
  171.    instead of a variable number of arguments directly.  */
  172. #ifdef __GNUC__
  173. extern int vprintf (const char *fmt, __gnuc_va_list ap);
  174. #else
  175. extern int vprintf (const char *fmt, __va_list ap);
  176. #endif
  177.  
  178. /* Similar to fprintf but it takes an argument list pointer 'ap'
  179.    instead of a variable number of arguments directly.  */
  180. #ifdef __GNUC__
  181. extern int vfprintf (FILE *stream, const char *fmt, __gnuc_va_list ap);
  182. #else
  183. extern int vfprintf (FILE *stream, const char *fmt, __va_list ap);
  184. #endif
  185.  
  186. /* Similar to sprintf but it takes an argument list pointer 'ap'
  187.    instead of a variable number of arguments directly.  */
  188. #ifdef __GNUC__
  189. extern int vsprintf (char *string, const char *fmt, __gnuc_va_list ap);
  190. #else
  191. extern int vsprintf (char *string, const char *fmt, __va_list ap);
  192. #endif
  193.  
  194. /* Read the next character as an unsigned char from the stream
  195.    'stream' and return its value, converted to an int.  EOF
  196.    is returned on read error/end-of-file.  */
  197. extern int fgetc (FILE *stream);
  198. extern int __filbuf (FILE *stream);
  199.  
  200. /* Similar to fgetc but implemented as a macro, so stream can be
  201.    evaluated more than once.  */
  202. extern int getc (FILE *stream);
  203. #define getc(p) \
  204.  (--((p)->__icnt) >= 0 ? *((p)->__ptr)++ : __filbuf(p))
  205.  
  206. /* Equivalent to getc with a stream of stdin.  */
  207. extern int getchar (void);
  208. #define getchar() getc(stdin)
  209.  
  210. /* Read chars from the stream 'stream' up to and including a
  211.    newline character and stores them in the string 's'. A null
  212.    character is added to mark the end of the string.  The number
  213.    of characters to read at most is 'count - 1'.  */
  214. extern char *fgets (char *s, int count, FILE *stream);
  215.  
  216. /* Read chars from the stream 'stdin' up to and including a
  217.    new line. The newline character is discarded.  */
  218. extern char *gets(char *s);
  219. extern int __flsbuf(int , FILE * );
  220.  
  221. /* Convert the character 'c' to type unsigned char and writes it
  222.    to stream 'stream'.  EOF is returned if an error occurs;
  223.    otherwise the character 'c' is returned.  */
  224. extern int putc (int c, FILE *stream);
  225.  
  226. #define putc(ch, p) \
  227.  (--((p)->__ocnt) >= 0 ? (*((p)->__ptr)++ = (ch)) : __flsbuf(ch,p))
  228.  
  229. extern int fputc (int c, FILE *stream);
  230.  
  231. /* Equivalent to putc with stdout as the value of the stream argument.  */
  232. extern int putchar (int ch);
  233. #define putchar(ch) putc(ch, stdout)
  234.  
  235.  
  236. /* Write the string 's' top the stream 'stream'. The terminating null
  237.    character is not written, and a newline character is not added, either.  */
  238. extern int fputs(const char *s, FILE *stream);
  239.  
  240. /* Write the string 's' to stdout.  */
  241. extern int puts (const char *s);
  242.  
  243. /* Pushes back the character 'c' onto the input stream 'stream'.
  244.    The next input from 'stream' will read 'c' before anything else.
  245.    If 'c' is EOF, ungetc does nothing and just returns EOF.  */
  246. extern int ungetc (int , FILE * );
  247.  
  248. /* Read up to 'count' objects of size 'size' into the array 'data',
  249.    from the stream 'stream'. Return the number of objects actually
  250.    read.  */
  251. extern size_t fread (void *data, size_t size, size_t count, FILE *stream);
  252.  
  253. /* Write up to 'count' objects of size 'size' from the array 'data',
  254.    to the stream 'stream'. The return value is normally 'count' if the
  255.    call succeeds.  */
  256. extern size_t fwrite (const void *data, size_t size, size_t count, FILE *stream);
  257.  
  258. /* Store the value of the file position indicator for the
  259.    stream 'stream' in the fpos_t object pointed to by 'position'.
  260.    fgetpos returns zero on success.  */
  261. extern int fgetpos(FILE *stream, fpos_t *position);
  262.  
  263. /* Change the file position of the stream 'stream'. 'whence'
  264.    must be one of the constants SEEK_SET, SEEK_CUR, SEEK_END,
  265.    to indicate the meaning of the relative 'offset'.  */
  266. extern int fseek(FILE *stream, long int offset, int whence);
  267.  
  268. /* Set the file position indicator for the stream 'stream' to the
  269.    position 'position', which must be set by a previous call to
  270.    fgetpos.  */
  271. extern int fsetpos(FILE *stream, const fpos_t *position);
  272.  
  273. /* Return the current file position of the stream 'stream'.
  274.    If a failure occurs, -1 is returned.  */
  275. extern long int ftell(FILE *stream);
  276.  
  277. /* Positions the stream 'stream' at the beginning of the file.
  278.    Equivalent to fseek (stream, 0, SEEK_SET).  */
  279. extern void rewind(FILE *stream);
  280.  
  281. /* Clears the end-of-file and error indicators for the stream
  282.    'stream'.  */
  283. extern void clearerr (FILE *stream);
  284.  
  285. /* Return nonzero if the end-of-file indicator for stream 'stream'
  286.    is set.  */
  287. extern int feof (FILE *stream);
  288. #define feof(stream) ((stream)->__flag & _IOEOF)
  289.  
  290. /* Return nonzero if the error indicator for the stream 'stream'
  291.    is set.  */
  292. extern int ferror (FILE *stream);
  293. #define ferror(stream) ((stream)->__flag & _IOERR)
  294.  
  295. /* Print an error message to the stream 'stderr'.
  296.  
  297.    If 'message' is null, the error message corresponding to
  298.    'errno' is printed.  */
  299. extern void perror (const char *message);
  300.  
  301. #ifdef __cplusplus
  302. }
  303. #endif
  304.  
  305. #endif
  306.